package core.util
{
	import flash.events.EventDispatcher;

	public class ConfigUtil extends EventDispatcher
	{
		public static const CONFIG_LOADED:String = "CONFIG_LOADED";
		
		public function ConfigUtil(lock:Lock)
		{
			if(lock == null)
			{
				throw new Error("ConfigUtil can not be init");
			}
		}
		
		private static var _config:ConfigUtil = null;
		public static function getInstance():ConfigUtil
		{
			if(_config == null)
			{
				_config = new ConfigUtil(new Lock());
			}
			return _config;
		}
		
		/////////////////////////////////////////////////////////////////////////////////////
		public var config:XML;
		public var cardConfig:XML;
		public function test():void
		{
			getStyleSet();
		}
		
		public function getCardClass(id:String):String
		{
			var cls:String = "flash.display.Sprite";
			var node:XMLList = cardConfig["card"].(@id==id);
			if(node.length()>0)
			{
				cls = node[0].@name
			}
			return cls;
		}
		
		public function getModuleByID(id:String):String
		{
			
			var node:XMLList = config["module-set"]["module"].(@id==id);
			
			if(node.length()>0)
			{
				var c:XML = node[0];
				return c.@src + "?ver=" + c.@ver;
			}
			else
			{
				trace("ConfigUtil getModuleByID Error");
				return "the " + id + " module does not exist";
			}
		}
		
		public function getStyleSet():Array
		{
			var style:Array = [];
			var node:XMLList = config["style-set"]["style"];
			for each(var n:XML in node)
			{
				style.push(n.@src+"?ver="+n.@ver);
			}
			return style;
		}
		
		public function getRSLSet():Array
		{
			var rsl:Array = [];
			var node:XMLList = config["rsl-set"]["rsl"];
			for each(var n:XML in node)
			{
				rsl.push(n.@src+"?ver="+n.@ver);
			}
			return rsl;
		}
	}
}
class Lock{}